package com.xh.sys.controller;

import com.xh.common.R;
import com.xh.sys.entity.SysFiles;
import com.xh.sys.service.SysFilesService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 * 附件功能表 前端控制器
 * </p>
 *
 * @author lhl
 * @since 2023-10-19
 */
@RestController
@RequestMapping("/sys-files")
@RequiredArgsConstructor
@Validated
public class SysFilesController {
    private final SysFilesService sysFilesService;


    @PostMapping("/save")
    public R<SysFiles> save(@RequestBody
                            @Validated
                                    SysFiles tosave) {
        boolean saveFlag = sysFilesService.saveOrUpdate(tosave);

        if (saveFlag) {
            return R.success(sysFilesService.getById(tosave.getId()));
        }
        return R.failed("保存失败");
    }

	/*@PostMapping("/queryByPage")
	public R<Page<SysFiles>> query(@RequestBody
								  @Validated ProjectQuery projectQuery) {
		Page<SysFiles> page1 = sysFilesService.page(projectQuery.getPageInfo(), projectQuery.queryWrapperBuild());
		return R.success(page1);
	}*/


    @PostMapping("/info/{id}")
    public R<SysFiles> info(@PathVariable
                            @Validated
                            @NotNull(message = "id不能空")
                                    Integer id) {

        SysFiles byId = sysFilesService.getById(id);
        return R.success(byId);
    }


    @PostMapping("/del")
    public R<SysFiles> del(@RequestBody
                           @Validated
                           @NotEmpty(message = "ids 集合不能空")
                                   List<Integer> ids) {
        sysFilesService.removeByIds(ids);
        return R.success("删除成功");
    }

}
